package leetcode.code0129;

import leetcode.helper.tree.TreeNode;

public class Solution {

	public int sumNumbers(TreeNode root) {
		return this.sumNumbers(root, 0);
	}

	private int sumNumbers(TreeNode root, int val) {
		val *= 10;
		val += root.val;
		if (root.left == null && root.right == null) {
			return val;
		}
		int ans = 0;
		if (root.left != null)
			ans += this.sumNumbers(root.left, val);
		if (root.right != null)
			ans += this.sumNumbers(root.right, val);
		return ans;
	}
}
